const db = require('../config/db');

class AllGroup {
  static sendMessage(senderId, message, callback) {
    const sql = 'INSERT INTO all_group_messages (sender_id, message) VALUES (?, ?)';
    db.run(sql, [senderId, message], function(err) {
      if (err) {
        return callback(err);
      }
      callback(null, this.lastID);
    });
  }

  static getMessages(callback) {
    const sql = 'SELECT * FROM all_group_messages ORDER BY timestamp ASC';
    db.all(sql, callback);
  }

  static getRecentMessages(limit, callback) {
    const sql = `
      SELECT * FROM all_group_messages 
      ORDER BY timestamp DESC 
      LIMIT ?`;
    db.all(sql, [limit], callback);
  }
}

module.exports = AllGroup; 